package com.supermarket.api.common.filters;

import com.alibaba.fastjson.JSONObject;
import com.supermarket.api.bean.user.LoginRes;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * 用户缓存管理
 * @author 李其伟
 * @date 2023/07/21
 */
public class UserCacheManage {

    private static final Map<String,String> TOKEN_CACHE = new ConcurrentHashMap<>();

    private static final String KEY = "user";

    /**
     * 设置用户信息
     */
    public static void setUserCache(String cacheValue) {
        TOKEN_CACHE.put(KEY,cacheValue);
    }

    /**
     * 获取用户信息
     */
    public static LoginRes getUserCache() {
        String cacheValue = TOKEN_CACHE.get(KEY);
        return JSONObject.parseObject(cacheValue,LoginRes.class);
    }

    /**
     * 获取用户ID
     */
    public static Long getUserIdCache() {
        return getUserCache().getId();
    }


}
